/*
 * 物料信息交易
 * 参数   交易码：trancode=12130
 * 
 */

package org.ccams.tran;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.ccams.domain.TMateriel;
import org.ccams.util.PageParameter;

public class Tran12130 extends AbstractJsonTran {

	@SuppressWarnings("unchecked")
	public void buildJSONObject(Map model, JSONObject json,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		int limit = Integer.parseInt(request.getParameter("limit"));
		int start = Integer.parseInt(request.getParameter("start"));
		String keyWords = request.getParameter("query");
		PageParameter page = new PageParameter();
		page.setLimit(limit);
		page.setStart(start);
		page.setKeyWords(keyWords);
		HashMap<String, Object> jsonMap = new HashMap<String, Object>();
		ArrayList<TMateriel> al = new ArrayList<TMateriel>();
		List<TMateriel> list = getCcamsService().getTmaterielDao().getTMaterielByPage(page);
		int count = getCcamsService().getTmaterielDao().getCount(page);
		
		for(TMateriel t : list){
			TMateriel u = new TMateriel();
			  u.setIdt_materiel(t.getIdt_materiel());
	          u.setMaterielno(t.getMaterielno());
	          u.setMaterielname(t.getMaterielname());
	          u.setSpec(t.getSpec());
	          u.setSpellcode(t.getSpellcode());
	          u.setMaterielclass(t.getMaterielclass());
	          u.setAttrib1(t.getAttrib1());
	          u.setAttrib2(t.getAttrib2());
	          u.setAttrib3(t.getAttrib3());
	          u.setAttrib4(t.getAttrib4());
	          u.setAttrib5(t.getAttrib5());
	          u.setAttrib6(t.getAttrib6());
	          u.setAttrib7(t.getAttrib7());
	          u.setAttrib8(t.getAttrib8());
	          u.setAttribunit1(t.getAttribunit1());
	          u.setAttribunit2(t.getAttribunit2());
	          u.setAttribunit3(t.getAttribunit3());
	          u.setAttribunit4(t.getAttribunit4());
	          u.setAttribunit5(t.getAttribunit5());
	          u.setAttribunit6(t.getAttribunit6());
	          u.setAttribunit7(t.getAttribunit7());
	          u.setAttribunit8(t.getAttribunit8());
	          u.setRemark(t.getRemark());
	          u.setState(t.getState());
			al.add(u);
		}
		JSONArray JsonArray = JSONArray.fromObject(al); //得到JSON数组 
		jsonMap.put("totalProperty", count);
        jsonMap.put("root", JsonArray);
        json.putAll(jsonMap);
	}
}
